<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="icon" th:href="@{/img/logo.ico}" href="../static/img/logo.ico" type="images/x-ico"/>

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="../static/css/bootstrap.min.css" th:href="@{/css/bootstrap.min.css}">
    <title>课程选报详情</title>
    <link rel="stylesheet" th:href="@{/fontawesome/css/font-awesome.min.css}"
          href="../../static/fontawesome/css/font-awesome.min.css">

    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,500;0,600;0,700;1,400&display=swap">

    <!-- Fontawesome CSS -->
    <link rel="stylesheet" href="../static/fontawesome/css/fontawesome.min.css"
          th:href="@{/fontawesome/css/fontawesome.min.css}">
    <link rel="stylesheet" href="../static/fontawesome/css/all.min.css" th:href="@{/fontawesome/css/all.min.css}">

    <!-- Main CSS -->
    <link rel="stylesheet" href="../static/css/back_index.css" th:href="@{/css/back_index.css}">
    <style type="text/css">
        th, td {
            white-space: nowrap;
            overflow: hidden;
            word-break: keep-all;
        }
    </style>
</head>
<body>
<div class="main-wrapper">
    <div th:replace="commons/bar::#menubar(activeUri1='课程管理',activeUri2='课程选报详情')"></div>

    <div class="page-wrapper">
        <div class="content container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <h1>课程选报详情</h1>
                    <hr>
                    <div class="form-inline col-sm-12">
                        <label class="control-label col-sm-1" for="coursename"><strong>名称</strong></label>
                        <input type="text" id="coursename" class="form-control form-control-sm col-sm-3">
                        <label class="control-label col-sm-1" for="selectcoursetype"><strong>类型</strong></label>
                        <select id="selectcoursetype" class="form-control form-control-sm col-sm-3"
                                data-live-search="true">
                            <option value="" selected="selected">请选择</option>
                            <option value="7">必修课</option>
                            <option value="0">专业选修课</option>
                            <option value="1">高新技术类</option>
                            <option value="2">跨学科领域类</option>
                            <option value="3">数学与自然科学类</option>
                            <option value="4">人文与社会科学类</option>
                            <option value="5">中华文明与外国文化类</option>
                            <option value="6">礼仪修养与语言表达类</option>
                        </select>
                    </div>
                    <hr>
                    <div class="fixed-table-toolbar">
                        <div class="bs-bars pull-left">
                            <span style="color: red">注：</span> <span>未出现课程代表暂无选报</span>
                        </div>
                        <div class="columns columns-right btn-group pull-right">
                            <div class="keep-open btn-group" title="列">
                                <button class="btn btn-default" type="button" name="refresh" title="刷新"
                                        onclick="myrefresh()">
                                    <i class="fa fa-refresh"></i></button>
                                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                    <i class="fas fa-table"></i><span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu" role="menu">
                                    <li>
                                        <input type="checkbox" checked="checked" id="td1" onclick="hiddenTD('td1')">ID
                                    </li>
                                    <li>
                                        <input type="checkbox" checked="checked" id="td2" onclick="hiddenTD('td2')">名称
                                    </li>
                                    <li>
                                        <input type="checkbox" checked="checked" id="td3" onclick="hiddenTD('td3')">选报人数
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td10" onclick="hiddenTD('td10')">类型
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td4" onclick="hiddenTD('td4')">学时
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td5" onclick="hiddenTD('td5')">学分
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td6" onclick="hiddenTD('td6')">开始选报时间
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td7" onclick="hiddenTD('td7')">结束选报时间
                                    </li>
                                    <li>
                                        <input type="checkbox" id="td8" onclick="hiddenTD('td8')">描述
                                    </li>
                                    <li>
                                        <input type="checkbox" checked="checked" id="td9" onclick="hiddenTD('td9')">操作
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="fixed-table-container table-responsive">
                        <table class="table table-hover table-striped table-bordered" id="datas">
                            <thead>
                            <th class="td1">ID</th>
                            <th class="td2">名称</th>
                            <th class="td3">选报人数</th>
                            <th class="td10" hidden="hidden">类型</th>
                            <th class="td4" hidden="hidden">学时</th>
                            <th class="td5" hidden="hidden">学分</th>
                            <th class="td6" hidden="hidden">开始选报时间</th>
                            <th class="td7" hidden="hidden">结束选报时间</th>
                            <th class="td8" hidden="hidden">介绍</th>
                            <th class="td9">操作</th>
                            </thead>
                            <tbody id="mytbody">
                            <tr id="template">
                                <td class="td1"></td>
                                <td class="td2"></td>
                                <td class="td3"></td>
                                <td class="td10" hidden="hidden"></td>
                                <td class="td4" hidden="hidden"></td>
                                <td class="td5" hidden="hidden"></td>
                                <td class="td6" hidden="hidden"></td>
                                <td class="td7" hidden="hidden"></td>
                                <td class="td8" hidden="hidden"></td>
                                <td class="td9"></td>
                            </tr>
                            </tbody>
                        </table>
                        <br/>
                        <div>
                            <div class="pull-left">
                                <input type="hidden" id="offset" value="0">
                                显示第<span id="begin"></span>到第<span id="end"></span>条记录，总共<span id="sum"></span>条记录。
                                每页显示
                                <select id="limit" onchange="changeLimit()">
                                    <option value="5">5</option>
                                    <option value="10" selected="selected">10</option>
                                    <option value="15">15</option>
                                    <option value="30">30</option>
                                    <option value="50">50</option>
                                    <option value="100">100</option>
                                </select> 条记录
                            </div>
                            <div class="pull-right">
                                <nav aria-label="Page navigation">
                                    <ul class="pagination" id="pages"></ul>
                                </nav>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="selectcourseModal" class="modal fade" tabindex="-1" role="dialog"
                     aria-labelledby="myLargeModalLabel" data-backdrop="static" data-keyboard="false">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4 class="modal-title" id="modal-h4"></h4>
                                <button type="button" class="close" data-dismiss="modal"
                                        aria-label="Close"><span
                                        aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <table class="table table-hover table-striped table-bordered" id="modal-datas"></table>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn btn-secondary" data-dismiss="modal">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
                <footer>
                    <p>2020 &copy; 软件学院学生信息管理系统 by 郑焙元</p>
                </footer>
            </div>
        </div>
    </div>
</div>
<script src="../static/js/jquery-3.5.1.min.js" th:src="@{/js/jquery-3.5.1.min.js}"></script>
<script>

    var limit;
    var begin = 1;
    var end = 0;
    var pageNum;
    var currentPage = 1;

    $(function () {
        limit = $("#limit option:selected").val();
        TableInit();
    })


    var TableInit = function () {
        sendAjax('/admin/api/selectcourse', 'get', {
            limit: $("#limit option:selected").val(),
            offset: $("#offset").val(),
            coursetype: $("#selectcoursetype option:selected").val(),
            coursename: $("#coursename").val()
        }, function (res) {
            paging(res);
            $.each(res.data, function (i, data) {
                var row = $("#template").clone();
                row.find(".td1").text(data.course.courseid);
                row.find(".td2").text(data.course.coursename);
                row.find(".td3").text(data.selectCourseStudents.length);
                row.find(".td10").text(switchCoursetype(data.course.coursetype));
                row.find(".td4").text(data.course.time);
                row.find(".td5").text(data.course.credits);
                row.find(".td6").text(data.course.begindate.substring(0, 10));
                row.find(".td7").text(data.course.enddate.substring(0, 10));
                row.find(".td8").text(data.course.info);
                let html = '<button type="button" class="btn btn-info btn-sm" data-toggle="modal" ' +
                    'data-target="#selectcourseModal" onclick="updateSelectCourse(\'' + data.course.courseid + '\', \'' + data.course.coursename + '\')">详情</button>';
                row.find(".td9").html(html);
                row.appendTo("#datas");//添加到模板的容器中
            });
            $("#template:first").remove();
        }, '');
    }

    function myrefresh() {
        $("#mytbody").children().remove();
        $("#mytbody").html('<tr id="template">\n' +
            '                                <td class="td1"></td>\n' +
            '                                <td class="td2"></td>\n' +
            '                                <td class="td3"></td>\n' +
            '                                <td class="td10" hidden="hidden"></td>\n' +
            '                                <td class="td4" hidden="hidden"></td>\n' +
            '                                <td class="td5" hidden="hidden"></td>\n' +
            '                                <td class="td6" hidden="hidden"></td>\n' +
            '                                <td class="td7" hidden="hidden"></td>\n' +
            '                                <td class="td8" hidden="hidden"></td>\n' +
            '                                <td class="td9"></td>\n' +
            '                            </tr>');
        TableInit();
        hiddenTD("td10");
        hiddenTD("td4");
        hiddenTD("td5");
        hiddenTD("td6");
        hiddenTD("td7");
        hiddenTD("td8");
    }

    function updateSelectCourse(courseid, coursename) {
        $("#modal-h4").text(coursename + "课程选报详情");
        $("#modal-datas").html('\n' +
            '                                    <thead>\n' +
            '                                    <th class="td1">学号</th>\n' +
            '                                    <th class="td2">姓名</th>\n' +
            '                                    <th class="td3">班级</th>\n' +
            '                                    </thead>\n' +
            '                                    <tbody id="modal-tbody">\n' +
            '                                    <tr id="modal-tr">\n' +
            '                                        <td class="td1"></td>\n' +
            '                                        <td class="td2"></td>\n' +
            '                                        <td class="td3"></td>\n' +
            '                                    </tr>\n' +
            '                                    </tbody>');

        sendAjax("/admin/api/selectcourse/" + courseid, "get", {
            courseid: courseid,
        }, function (res) {
            $.each(res.data, function (i, student) {
                var row = $("#modal-tr").clone();
                row.find(".td1").text(student.studentid);
                row.find(".td2").text(student.studentname);
                row.find(".td3").text(student.studentclassid);
                row.appendTo("#modal-datas");//添加到模板的容器中
            });
            $("#modal-tr:first").remove();
        }, '');
    }
</script>
<script src="../static/js/popper.min.js" th:src="@{/js/popper.min.js}"></script>
<script src="../static/js/bootstrap.min.js" th:src="@{/js/bootstrap.min.js}"></script>

<!-- Slimscroll JS -->
<script src="../static/js/jquery.slimscroll.min.js" th:src="@{/js/jquery.slimscroll.min.js}"></script>

<!-- Custom JS -->
<script src="../static/js/script.js" th:src="@{/js/script.js}"></script>

</body>
</html>
